import React, { useEffect, useState } from 'react'
import { nanoid } from 'nanoid'
import Header from "./components/Header"
import List from "./components/List"
import Footer from "./components/Footer"
import "./App.css"

export default function App() {

  const [todoList, setTodoList] = useState([])

  // 刚渲染App的时候去本地存储中查看是否保存有数据
  useEffect(() => {
    setTodoList(JSON.parse(localStorage.getItem("todoList")) || [])
  }, [])



  // 监听todoList 发生改变就在本地保存
  useEffect(() => {
    localStorage.setItem("todoList", JSON.stringify(todoList))
  }, [todoList])



  return (
    <div className="todo-container">
      <div className="todo-wrap">
        <Header setTodoList={setTodoList} todoList={todoList} />
        <List todoList={todoList} setTodoList={setTodoList} />
        <Footer todoList={todoList} setTodoList={setTodoList} />
      </div>
    </div>
  )
}

